﻿
@{
    ViewData["Title"] = "Edit";
}
@using ViewModel.admin
@model sys_adminVm


<div class="weadmin-body" id="divEdit" >
    <form class="layui-form">
        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="we-red">*</span>登录名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="admin_name" v-model="model.admin_name" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="we-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="we-red">*</span>手机
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="admin_tel" required="" v-model="model.admin_tel" lay-verify="required"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="we-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
               角色
            </label>
            <div class="layui-input-inline">
                <select id="Selgid" >
                    <option value="0" >无</option>
                    @foreach(sys_admin_groupVm item in ViewBag.groups as List<sys_admin_groupVm>)
                    {
                        <option value="@item.id" >@item.gname</option>
                    }
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否超级管理员</label>
            <div class="layui-input-block">
                <input type="checkbox" name="switch" v-if="model.admin_is_super" lay-filter="admin_is_super" lay-skin="switch" lay-text="是|否" checked="checked" />
                <input type="checkbox" name="switch" v-else lay-filter="admin_is_super" lay-skin="switch" lay-text="是|否" />
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span v-if="model.id==0" class="we-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass" name="pass" v-if="model.id==0" v-model="model.admin_password" lay-verify="required"
                       autocomplete="off" class="layui-input">
                <input type="password" id="L_pass" name="pass" v-else v-model="model.admin_password"
                       autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span v-if="model.id==0" class="we-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_repass" name="repass" v-if="model.id==0" v-model="model.admin_oldpassword" lay-verify="required"
                       autocomplete="off" class="layui-input">
                <input type="password" id="L_repass" name="repass" v-else v-model="model.admin_oldpassword"
                       autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label"></label>
            <button class="layui-btn" v-if="model.id==0" lay-filter="add" type="button" lay-submit="">增加</button>
            <button class="layui-btn" v-else lay-filter="add" type="button" lay-submit="">修改</button>
        </div>
    </form>
</div>

@section Scripts
{
        <script type="text/javascript">
            var model=@Html.Raw(Newtonsoft.Json.JsonConvert.SerializeObject(Model))

            var vm = new Vue({
                el: '#divEdit',
                data: {
                   model:model
                },
                methods: {
                    submit: function () {
                        
                        //// 获得frame索引
                        //var index = parent.layer.getFrameIndex(window.name);
                        ////关闭当前frame
                        //parent.layer.close(index);
                    }
                }
            })


            layui.extend({
                admin: '{/}../../static/js/admin'
            });
            layui.use(['form', 'layer', 'admin'], function () {
                    var form = layui.form;
                form.on('switch(admin_is_super)', function (data) {
                        var x = data.elem.checked;
                        vm.model.admin_is_super = x;
                        return false;
                });

                form.on('submit(add)', function (data) {
                    vm.model.admin_gid = $(".layui-this").attr("lay-value");
                    $.post("@Url.Action("EditAction")", { sav: JSON.stringify(vm.model) }, function (data) {
                            layer.msg('操作成功！', {
                                icon: 1
                            }, function () {
                                parent.location.href = parent.location.href;
                                });
                        })
                    //这样子点击就会触发该验证方法.
                    return false;
                })
            })

            $(function () {
                $("#Selgid").val('@Model.admin_gid');
            })

        </script>
}